package com.esri.core.tasks.tilecache;

import com.esri.core.internal.util.d;
import com.esri.core.tasks.ags.geoprocessing.GPJobResource;
import java.io.IOException;
import java.io.StringWriter;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class ExportTileCacheStatus {
    private static final String JOB_ID_FIELD = "jobID";
    private static final String SERVICE_URL_FIELD = "serviceUrl";
    private String _downloadFilename;
    private long _downloadSize;
    private long _filesRead;
    private boolean _isDownloading;
    private long _totalFiles;
    private long _totalRead;
    private String mJobId;
    private TileCacheJobResource mJobResource;
    private String mServiceUrl;

    /* JADX INFO: Access modifiers changed from: package-private */
    public ExportTileCacheStatus(String str, String str2) {
        this.mServiceUrl = str;
        this.mJobId = str2;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public ExportTileCacheStatus(TileCacheJobResource tileCacheJobResource, String str) {
        this.mJobResource = tileCacheJobResource;
        this.mServiceUrl = str;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public ExportTileCacheStatus(TileCacheJobResource tileCacheJobResource, long j, long j2, String str, long j3, long j4) {
        this.mJobResource = tileCacheJobResource;
        this._filesRead = j;
        this._totalFiles = j2;
        this._downloadFilename = str;
        this._totalRead = j3;
        this._downloadSize = j4;
        this._isDownloading = true;
    }

    protected ExportTileCacheStatus() {
    }

    public GPJobResource.JobStatus getStatus() {
        GPJobResource.JobStatus jobStatus = GPJobResource.JobStatus.SUBMITTED;
        if (this._isDownloading) {
            if (this._filesRead == this._totalFiles && this._totalRead == this._downloadSize) {
                return GPJobResource.JobStatus.SUCCEEDED;
            }
            return GPJobResource.JobStatus.EXECUTING;
        }
        TileCacheJobResource tileCacheJobResource = this.mJobResource;
        return tileCacheJobResource != null ? tileCacheJobResource.getJobStatus() : jobStatus;
    }

    public String getJobID() {
        String str = this.mJobId;
        TileCacheJobResource tileCacheJobResource = this.mJobResource;
        return tileCacheJobResource != null ? tileCacheJobResource.getJobID() : str;
    }

    public String getUrl() {
        return this.mServiceUrl;
    }

    public GPJobResource getJobResource() {
        return this.mJobResource.getGPJobResource();
    }

    public TileCacheJobResource getTileCacheJobResource() {
        return this.mJobResource;
    }

    public boolean isDownloading() {
        return this._isDownloading;
    }

    public long getTotalFilesDownloaded() {
        return this._filesRead;
    }

    public long getTotalFiles() {
        return this._totalFiles;
    }

    public String getDownloadFilename() {
        return this._downloadFilename;
    }

    public long getTotalBytesDownloaded() {
        return this._totalRead;
    }

    public long getDownloadSize() {
        return this._downloadSize;
    }

    public static ExportTileCacheStatus fromJson(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            ExportTileCacheStatus exportTileCacheStatus = new ExportTileCacheStatus();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (currentName.equals(SERVICE_URL_FIELD)) {
                    exportTileCacheStatus.mServiceUrl = jsonParser.getText();
                } else if (currentName.equals(JOB_ID_FIELD)) {
                    exportTileCacheStatus.mJobId = jsonParser.getText();
                } else {
                    jsonParser.skipChildren();
                }
            }
            return exportTileCacheStatus;
        }
        return null;
    }

    public String toJson() throws IOException {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = d.a(stringWriter);
        a.writeStartObject();
        a.writeStringField(SERVICE_URL_FIELD, this.mServiceUrl);
        a.writeStringField(JOB_ID_FIELD, getJobID());
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }
}
